function dividing(module) {
    console.log('==========================================');
    console.log(module + ':');
    console.log('');
}

dividing('常规语法');
// 常规语法
function* gen() {
    let value = 0;
    let result;
    while (1) {
        result = yield ++value; // result 就是通过 next(val) 传递过来的(注意调用第一个 next 时没有值)
        console.log(result);
        if (result === 'end') {
            return;
        }
    }
}
const fn = gen();
console.log(fn.next()); // 返回 yield 表达式产生的值.
console.log(fn.next(12));
// console.log(fn.throw()); // 向生成器抛出错误.
console.log(fn.return(12)); // 返回给定的值并结束生成器.

dividing('yield*');
// yield*
// Generator 函数内部需要调用另外一个 Generator 函数时会用到 yield*
function* obj() {
    yield "1";
    yield "2";
    yield "3";
}
function* objects() {
    yield* obj();
    yield "cat";
    yield "dog";
    yield "duck";
}
function* say() {
    yield* objects();
    yield " say hello world!";
    yield " say hello world!1212";
}

const fn1 = say();
console.log(fn1.next());
console.log(fn1.next());
console.log(fn1.return()); // 只是结束内部的 Generator
console.log(fn1.next());
console.log(fn1.return());
console.log(fn1.next());
console.log(fn1.next());